<?php
namespace Wx\Controller;
use Think\Controller;

class UserPayListController extends CommonController {
	//今日收益明细——0-线下收银1-门店拼团2-乡村拼团3-积分兑换
	public function paylist(){
		$uid=session('u_id');
		if($uid>0){
			
			$shop_credit=0;
			if($_GET['shop_credit']>0)$shop_credit=$_GET['shop_credit'];
			
			$member_credit_log=D('member_credit_log');
			$year = date("Y");
			$month = date("m");
			$day = date("d");
			$start = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
			$end= mktime(23,59,59,$month,$day,$year);//当天结束时间戳
			//dump($start);dump($end);echo date('Y-m-d H:i:s',$start);echo date('Y-m-d H:i:s',$end);
			$credit_arr=$member_credit_log->where("u_id=".$uid." and credit_type like 'credit3' and shop_credit=".$shop_credit." and (changetime>".$start." and changetime<".$end.") ")->order("id desc")->select();
			$credit_total=$member_credit_log->where("u_id=".$uid." and credit_type like 'credit3' and shop_credit=".$shop_credit." and (`change_type` LIKE '+') and (changetime>".$start." and changetime<".$end.") ")->order("id desc")->sum('change_number');
			if($credit_total==null)$credit_total=0;
			
			if($shop_credit==0)$title='线下收银';
			if($shop_credit==1)$title='门店拼团';
			if($shop_credit==2)$title='乡村拼团';
			if($shop_credit==3)$title='积分兑换';
			$this->assign('title',$title);//类型
			$this->assign('shop_credit',$shop_credit);//类型
			$this->assign('credit_total',$credit_total);//今日总收益
			$this->assign('credit_arr',$credit_arr);
			$this->display('balance-offline');
		}else{
			$this->error('您已离线！');
		}//end if
        
	}//end fun
	//历史明细查询
	public function paylist_history(){
		$uid=session('u_id');
		if($uid>0){
			
			$shop_credit=0;
			if($_GET['shop_credit']>0)$shop_credit=$_GET['shop_credit'];
			
			$member_credit_log=D('member_credit_log');
			if($_POST['start-time']!=''){
				//dump($_POST['start-time']);dump($_POST['end-time']);
				$start_time=explode("-",$_POST['start-time']);
				$end_time=explode("-",$_POST['end-time']);
				//dump($start_time);dump($end_time);die;
				$start = mktime(0,0,0,$start_time[1],$start_time[2],$start_time[0]);//当天开始时间戳
				$end= mktime(23,59,59,$end_time[1],$end_time[2],$end_time[0]);//当天结束时间戳
				if($start>$end){
					//错误页面的默认跳转页面是返回前一页，通常不需要设置
    				$this->error('起止时间错误！');
				}
			}else{
				$year = date("Y");
				$month = date("m");
				$day = date("d");
				$start = mktime(0,0,0,$month,$day-1,$year);//当天开始时间戳
				$end= mktime(23,59,59,$month,$day-1,$year);//当天结束时间戳
			}
			
			//dump($start);dump($end);echo date('Y-m-d H:i:s',$start);echo date('Y-m-d H:i:s',$end);
			
			$credit_arr=$member_credit_log->where("u_id=".$uid." and credit_type like 'credit3' and shop_credit=".$shop_credit." and (changetime>".$start." and changetime<".$end.") ")->order("id desc")->select();
			$credit_total=$member_credit_log->where("u_id=".$uid." and credit_type like 'credit3' and shop_credit=".$shop_credit." and (`change_type` LIKE '+') and (changetime>".$start." and changetime<".$end.") ")->order("id desc")->sum('change_number');
			if($credit_total==null)$credit_total=0;
			
			if($shop_credit==0)$title='线下收银';
			if($shop_credit==1)$title='门店拼团';
			if($shop_credit==2)$title='乡村拼团';
			if($shop_credit==3)$title='积分兑换';
			$this->assign('start',date('Y-m-d',$start));
			$this->assign('end',date('Y-m-d',$end));
			$this->assign('title',$title);//类型
			$this->assign('shop_credit',$shop_credit);//类型
			$this->assign('credit_total',$credit_total);//今日总收益
			$this->assign('credit_arr',$credit_arr);
			$this->display('balance-offline-his');
		}else{
			$this->error('您已离线！');
		}//end if
	}//end fun
}//end class